<template>
  <div class="app-container">
    <div class="ces-main">


      <el-form ref="form" :model="FormData" :inline="true" :rules="rules" label-position="right" label-width="120px">
        <el-form-item style="height:30px">

          <el-button type="primary" icon="el-icon-search" size="small" @click="getDataList">查询</el-button>
          <el-button type="primary" icon="el-icon-search" size="small" @click="FunRowAdd">添加</el-button>

        </el-form-item>
        <Search-Form ref="form" size='mini' labelWidth='50px' :searchData='Search' :inline="true" :tableCols='tableCols'
          :searchHandle="searchHandle"></Search-Form>
      </el-form>
      <ces-table size='mini' :isSelection='true' :isIndex='true' :isSearch='true' :isHandle='false'
        :IsfunEdit='IsfunEdit' :Isfunfail='Isfunfail' :tableData='tableData' :tableCols='tableCols' :Search='Search'
        @refresh="refresh" @handleEdit='handleEdit' @SelectionChange='handleSelectionChange' @handleDelete="delData">
      </ces-table>
    </div>
  </div>
</template>

<script>


//引入组件

import cesTable from "../Common//table.vue";
import SearchForm from "../Common//Search.vue";
import MianForm from "../Common//form.vue";

import { funDownload, GetTableColsData } from "@/api/Common";
import { getDataList, UpdateForm, DeleteForm } from '@/api/Mespurchase/PUOrder';
import vGetToolBar from "../Common/GetToolBar";

export default {
  data() {
    //表单查询一般分为input，下拉框，和日期，下面是下拉框时的设置下拉信息的情况，我的项目没有用到，但是留着方便看

    return {
      MenuCode: "A050302",
      tableData: [],//表格数据
      tableCols: [],//表格列数据
      multipleTable: [],
      ParmType: "",
      ParmName: "",
      CustomerCode: "",
      searchHandle: [],
      Isjudge: false,
      IsfunEdit: false,
      Isfunfail: false,
      Search: {
        // 查询条件
        total: 0, // 总记录数
        pageSize: 13, // 一页显示的记录数
        page: 1, // /当前页码
        RNO: "003", // 表编号  根据Controller中对应的表编号
        jsWhere: this.sqlwhere, // 自定义条件
        CustomerCode: this.ParmName

      },
      cities: [
        {
          value: "0",
          label: "草稿",
        },
        {
          value: "1",
          label: "审核中",
        },
        {
          value: "2",
          label: "结案",
        },
        {
          value: "3",
          label: "作废",
        },
      ],
      SearchDialog: false,
      DialogBtnMargin: 0,
      dialogVisible: false,

    }
  },

  components: { //引入组件后注册组件
    cesTable,
    vGetToolBar,
    SearchForm,
    MianForm
  },
  mounted() {
    this.getTableCols()
    this.getDataList()
  }, props: {
    ParmType: String,
    ParmName: String,
    sqlwhere: String,
    required: true
  },
  methods: {
    //搜索重置
    refresh() {
      this.getDataList();
    },
    reform() {
      this.Search = {
        // 查询条件
        // total: 0, // 总记录数
        pageSize: 13, // 一页显示的记录数
        page: 1, // /当前页码
        RNO: "003", // 表编号  根据Controller中对应的表编号
        jsWhere: " and isnull(Status,0)=2", // 自定义条件
      };
      this.getDataList();
    },
    //读取列配置
    async getTableCols() {
      this.tableCols = []
      const res = await GetTableColsData({ InterID: "346" });
      this.tableCols = res.data;

    },
    async getDataList() {
      const res = await getDataList({ data: JSON.stringify(this.Search) });
      this.tableData = res.data.Table;

      //将data 中的数据放到DataList中
      this.Search.total = res.data.Table1[0].RecordCount;

    }, OpenFindForm() {
      //打开搜索框
      this.SearchDialog = true;
      //计算外边距
      console.log(this.$refs.searchDialog.offsetHeight);
      this.DialogBtnMargin = this.$refs.searchDialog.offsetHeight - 40;
    }, handlexportData() {
      funDownload("346", JSON.stringify(this.Search));
    }, async handeAdd() {
      // 新建

      this.$emit('FunrRowsAdd', this.multipleTable, this.ParmType);

    }
    , handleSelectionChange(val) {

      this.multipleTable = val;

    }

    , FunRowAdd() {

      this.Isjudge = true;
      for (let v of this.multipleTable) {

        if (this.CustomerCode != "" && this.CustomerCode != v.CustomerCode) {
          this.Isjudge = false;
          break;
        } else {
          this.CustomerCode = v.CustomerCode;
        }

      }
      if (this.Isjudge) {
        this.$emit('FunRowAdd', this.multipleTable, this.ParmType);
      } else {
        this.$notify({
          title: "不能添加",
          dangerouslyUseHTMLString: true,
          message: "只能添加相同的客户",
          type: "error",
        });
      }


    }


  }
}
</script>

<style lang="scss" scoped>
.app-container {
  .EditObjs-table {
    margin-top: 30px;
  }

  .permission-tree {
    margin-bottom: 5px;
  }
}

.searchDialog ::v-deep .el-dialog__header {
  background: #409eff;
}

.searchDialog ::v-deep .el-dialog__title {
  color: #fff;
}

.searchDialog ::v-deep .el-dialog__headerbtn .el-dialog__close {
  color: #fff;
}
</style>